<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <img src="img/on.gif" alt="">
   <script>
       let i=1;
        document.querySelector("img").onclick=function () {
            if (i==0) {
                document.querySelector("img").src = "img/off.gif";
                i = 1;
            }else{
                document.querySelector("img").src="img/on.gif";
                i=0;
            }
        }
    </script>
</body>
</html>